﻿@using System.Text;
@using Blazorise.Extensions;
@inherits Blazorise.Progress
<CascadingValue Value="@this" IsFixed>
    <CascadingValue Value="@State">
        @if ( HasProgressBar )
        {
            <div class="@HasProgressBarClassNames">
                @ChildContent
            </div>
        }
        else
        {
            <div @ref="@ElementRef" id="@ElementId" class="@ClassNames" style="@StyleNames" @attributes="@Attributes">
                <div class="@InnerClassNames" style="@($"width: {Percentage}%;")">@ChildContent</div>
            </div>
        }
    </CascadingValue>
</CascadingValue>
@code {
    string HasProgressBarClassNames
    {
        get
        {
            var sb = new StringBuilder( "w-full bg-gray-200 rounded-full dark:bg-gray-700 mb-3 flex overflow-hidden" );

            if ( ChildContent == null )
            {
                sb.Append( " " ).Append( ClassProvider.ProgressSize( ThemeSize ) );
            }

            return sb.ToString();
        }
    }

    string InnerClassNames
    {
        get
        {
            var sb = new StringBuilder( "text-xs font-medium text-center p-0.5 leading-none rounded-full" );

            if ( Color.IsNotNullOrDefault() )
            {
                sb.Append( " " ).Append( ClassProvider.ProgressBarColor( Color ) );
            }

            if ( ChildContent == null )
            {
                sb.Append( " " ).Append( ClassProvider.ProgressSize( ThemeSize ) );
            }

            if ( Striped )
            {
                sb.Append( " bg-striped" );
            }

            if ( Animated )
            {
                sb.Append( " bg-striped-animated" );
            }

            if ( Indeterminate )
            {
                sb.Append( " progress-bar-indeterminate" );
            }

            return sb.ToString();
        }
    }
}